#include<stdio.h>
#include<string.h>
#include<assert.h>
#include<stdlib.h>
#include<errno.h>
int my_strcmp(const char* str1,const char* str2)
{
	assert(str1&&str2);
	while (*str1==*str2)
	{
		if (*str1 == '\0')
			return 0;
		str1++;
		str2++;
	}
	return (*str1 - *str2);
}
char* my_strstr(const char* str1, const char* str2)
{
	assert(str1&&str2);
	const char* s1 = str1;
	const char* s2 = str2;
	const char* p = str1;
	while (*p)
	{
		s1 = p;
		s2 = str2;
		while (*s1 != '\0'&&*s2 != '\0'&&*s1 == *s2)
		{
			++s1;
			++s2;
		}
		if (*s2 == '\0')
		{
			return (char*)p;
		}
		p++;
	}
	return NULL;
}
void* my_memcpy(void* dest,const void* source,size_t num)
{
	assert(dest&&source);
	void* ret = dest;
	while (num--)
	{
		*(char*)dest = *(char*)source;
		dest = (char*)dest;
		source = (char*)source + 1;
	}
	return ret;
}
void* my_memmove(void* dest, const void* source, size_t num)
{
	char* arr = (char*)malloc(num);
	char* p = arr;
	char* p1 = arr;
	void* ret = dest;
	int m = num;
	while (m--)
	{
		*p = *(char*)source;
		p++;
		source = (char*)source + 1;
	}
	while (num--)
	{
		 *(char*)dest=*p1;
		p1++;
		dest = (char*)dest + 1;
	}
	free(arr);
	arr = NULL;
	return ret;
}
int main()
{
	/*char arr1[20] = "abc";
	char arr2[] = "abcd";
	int ret = my_strcmp(arr1, arr2);
	if (ret < 0)
	{
		printf("<\n");
	}
	else if (ret==0)
	{
		printf("==\n");
	}
	else
	{
		printf(">\n");
	}*/
	/*char arr1[20] = "abcdef";
	char arr2[] = "bit";
	strncpy(arr1+1, arr2, 5);
	printf("%s\n", arr1);*/

	/*char arr[20] = "hello";
	char arr1[] = "bit";
	strncat(arr, arr1, 5);
	printf("%s\n", arr);*/
	/*const char* sep = "@.";
	char email[] = "zhangpenwei@bittejiuyeke.com";
	char cp[40] = { 0 };
	strcpy(cp,email);

	char* ret=strtok(cp, sep);
	printf("%s\n", ret);

	ret = strtok(NULL, sep);
	printf("%s\n", ret);

	ret = strtok(NULL, sep);
	printf("%s\n", ret);*/


	/*char str[] = "this is a simple string";
	char * pch;
	pch = my_strstr(str, "simple");
	if (pch != NULL)
	{
		printf("%s\n", pch);
	}*/

	int arr[20] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	my_memmove(arr+2,arr,20);
	for (int i = 0; i < sz; i++)
	{
		printf("%d ", arr[i]);
	}

	/*char* arr = "abcdef";
	char* arr1="abc";
	char* p = strstr(arr, arr1);
	printf("%s\n", p);*/

	/*FILE* pf = fopen("tewt.txt", "r");
	if (pf == NULL)
	{
		printf("%s\n", strerror(errno));
		return 1;
	}*/
	return 0;
}